home *** CD-ROM | disk | FTP | other *** search
/ Whiteline: delta / whiteline CD Series - delta.iso / tex / style / misc / dates.sty < prev    next >
Text File  |  1995-11-25  |  12KB  |  289 lines

  1. % --- ------------------------------------------------------------------
  2. % ---                            dates.sty
  3. % ---          Flexible Date Macros for LaTeX, version 1.00--1
  4. % --- ------------------------------------------------------------------
  5. % ---         Adrian F. Clark  (alien@uk.ac.essex)   4-Aug-1992
  6. % --- ------------------------------------------------------------------
  7. %
  8. % --- \today            generates today's date.  Alter this to suit
  9. % ---                   the way you want it to appear.  It is currently
  10. % ---                   set up to generate dates in the form
  11. % ---                          `Thursday 4th October 1066'
  12. %
  13. % --- \thisdayofweek    generates today's day name (`Sunday', etc).
  14. % --- \thisday          generates today's day (`1', `2', etc).
  15. % --- \thisdayth        generates today's day (`1st', `2nd', etc),
  16. % ---                   where the `st' etc are generated by \st etc.
  17. % --- \thismonth        generates today's month (`January', etc).
  18. % --- \thisyear         generates today's year.
  19. % --- \thisphaseofmoon  generates the current phase of the moon.
  20. %
  21. % --- \dayofweek{year}{month}{day}  generates the day of the week for
  22. %            the given date.
  23. %
  24. % --- \phaseofmoon{year}{month}{day}  generates the phase of the moon
  25. %            for the given date.
  26. %
  27. % --- \Sunday (etc)   generates `Sunday' (etc).
  28. % --- \January (etc)  generates 'January' (etc).
  29. % --- \NewMoon (etc)  generates `new' (etc).
  30. %
  31. % --- \st    generates a raised, reduced, underlined `st', as in 1st.
  32. % --- \nd    generates a raised, reduced, underlined `nd', as in 2nd.
  33. % --- \rd    generates a raised, reduced, underlined `rd', as in 3rd.
  34. % --- \th    generates a raised, reduced, underlined `th', as in 4th.
  35.  
  36. % --- ------------------------------------------------------------------
  37. % --- The actual date macros.
  38.  
  39. % --- As distributed, \today generates today's date in the style
  40. % --- `Thursday 4th October 1066'.  
  41.  
  42. \def\today{\thisdayofweek\ \thisdayth\ \thismonth\ \thisyear}
  43.  
  44. \def\thisday{\number\day}
  45.  
  46. \def\thisdayth{\thisday \ifcase\day
  47.   \or\st\or\nd\or\rd\or\th\or\th\or\th\or\th\or\th\or\th\or\th
  48.   \or\th\or\th\or\th\or\th\or\th\or\th\or\th\or\th\or\th\or\th
  49.   \or\st\or\nd\or\rd\or\th\or\th\or\th\or\th\or\th\or\th\or\th\or\st\fi}
  50.  
  51. \def\thisdayofweek{\dayofweek{\year}{\month}{\day}}
  52.  
  53. \def\thismonth{\ifcase\month\or \January\or \February\or \March\or
  54.   \April\or \May\or \June\or \July\or \August\or \September\or
  55.   \October\or \November\or \December\fi}
  56.  
  57. \def\thisyear{\number\year}
  58.  
  59. \def\thisphaseofmoon{\phaseofmoon{\year}{\month}{\day}}
  60.  
  61. % --- ------------------------------------------------------------------
  62. % --- Names of days of the week, the months, and the phases of the moon.
  63. % --- This makes it easier to change them for languages other than English.
  64. % --- (And that's why they're not \@Sunday, etc).
  65.  
  66. \def\Sunday{Sunday}
  67. \def\Monday{Monday}
  68. \def\Tuesday{Tuesday}
  69. \def\Wednesday{Wednesday}
  70. \def\Thursday{Thursday}
  71. \def\Friday{Friday}
  72. \def\Saturday{Saturday}
  73.  
  74. \def\January{January}
  75. \def\February{February}
  76. \def\March{March}
  77. \def\April{April}
  78. \def\May{May}
  79. \def\June{June}
  80. \def\July{July}
  81. \def\August{August}
  82. \def\September{September}
  83. \def\October{October}
  84. \def\November{November}
  85. \def\December{December}
  86.  
  87. \def\NewMoon{new}
  88. \def\WaxCresMoon{waxing crescent}
  89. \def\FirstQuarterMoon{in its first quarter}
  90. \def\WaxGibMoon{waxing gibbous}
  91. \def\FullMoon{full}
  92. \def\WaneGibMoon{waning gibbous}
  93. \def\LastQuarterMoon{in its last quarter}
  94. \def\WaneCresMoon{waning crescent}
  95.  
  96.  
  97. % --- ------------------------------------------------------------------
  98. % --- Counters.  Note that we use the same registers as TeX holds other
  99. % --- things in (e.g., \count0 holds the page number).  This requires
  100. % --- that \@savestyle, \@setstyle, \dayofweek and \phaseofmoon perform
  101. % --- all their register manipulations within a group.  This may seem
  102. % --- a bit messy, but it saves having eight registers permanently set
  103. % --- aside just for date calculation.
  104.  
  105. \def\@cent{\count0 }                       % century number (1979 == 20)
  106. \def\@diy{\count1 }                        % day in the year
  107. \def\@dow{\count2 }                        % gets day of the week
  108. \def\@epact{\count3 }                      % age of the moon on Jan. 1
  109. \def\@golden{\count4 }                     % Moon's golden number
  110. \def\@leap{\count5 }                       % leap year fingaler
  111. \def\@x{\count6 }                          % temp register
  112. \def\@y{\count7 }                          % another temp register
  113.  
  114. % --- ------------------------------------------------------------------
  115. % --- For `old' (pre version 2.10) LaTeX, these macros ensure the
  116. % --- smaller text comes out in the right font by saving the font
  117. % --- family before reducing the size, then restoring it.
  118. % --- (This hack was suggested by Leslie Lamport.)  Of course, it
  119. % --- requires that the font in use when the caller is invoked has
  120. % --- a sensible family.
  121.  
  122. % --- For LaTeX 2.10 onwards, which uses the font selection scheme due
  123. % --- to Mittelbach and Shoepf, such a hack is not necessary.  The
  124. % --- macros detect which version is in use automagically.
  125.  
  126. \def\st{\alien@up{st}}
  127. \def\nd{\alien@up{nd}}
  128. \def\rd{\alien@up{rd}}
  129. \def\th{\alien@up{th}}
  130.  
  131. \def\alien@up#1{{\@savestyle\thinspace$^{\underline{\hbox{%
  132.   \scriptsize\@setstyle#1\fam=-1 }}}$}}
  133.  
  134. % --- Macros to save and restore the font family.
  135.  
  136. \def\@savestyle{\count0=\the\fam}
  137.  
  138. \def\@setstyle{\ifcase\count0\rm\or\mit\or\cal\or\rm% what's family 3?
  139.   \or\it\or\sl\or\bf\or\tt\fi}
  140.  
  141. % --- ------------------------------------------------------------------
  142. % --- The nitty-gritty.
  143.  
  144. % --- The day of the week (\Sunday, etc.) is inserted into the text
  145. % --- by \dayofweek. (This uses registers \@dow, \@leap, \@x and \@y.)
  146. % --- I acquired this from elsewhere; it was apparently written by
  147. % --- Martin Minow, now a DEC employee.  The algorithms is:
  148. % ---   leap = year + (month - 14)/12;
  149. % ---   dow = (13 * (month + 10 - (month + 10)/13*12) - 1)/5
  150. % ---   dow += day + 77 + 5 * (leap % 100)/4
  151. % ---   dow += leap / 400
  152. % ---   dow -= leap / 100 * 2
  153. % ---   dow = (dow % 7)
  154.  
  155. \def\dayofweek#1#2#3{{\@leap=#2\advance\@leap by -14\divide\@leap by 12\relax
  156.   \advance\@leap by #1\relax
  157.   \@dow=#2\advance\@dow by 10\relax
  158.   \@y=\@dow \divide\@y by 13\multiply\@y by 12\relax
  159.   \advance\@dow by -\@y \multiply\@dow by 13\relax
  160.      \advance\@dow by -1 \divide\@dow by 5\relax
  161.   \advance\@dow by #3\advance\@dow by 77\relax
  162.   \@x=\@leap \@y=\@x \divide\@y by 100\multiply\@y by 100\relax
  163.      \advance\@x by -\@y \relax
  164.   \multiply\@x by 5\divide\@x by 4\advance\@dow by \@x
  165.   \@x=\@leap \divide\@x by 400\advance\@dow by \@x
  166.   \@x=\@leap \divide\@x by 100\multiply\@x by 2\advance\@dow by -\@x
  167.   \@x=\@dow \divide\@x by 7\multiply\@x by 7\advance\@dow by -\@x
  168.   \ifcase\@dow \Sunday\or \Monday\or \Tuesday\or \Wednesday\or
  169.       \Thursday\or \Friday\or \Saturday\fi}}
  170.  
  171. \endinput
  172.  
  173. %
  174. % --- Likewise, \phaseofmoon inserts the phase of the moon into the
  175. % --- text. This was written by the same person as \dayofweek.
  176. % --- The routine calculates the year's epact (the age of the moon on Jan 1.),
  177. % --- adds this to the number of days in the year, and calculates the phase
  178. % --- of the moon for this date.  It returns the phase as a string, e.g.,
  179. % --- \NewMoon, \FullMoon, etc.
  180. %
  181. % --- In the algorithm:
  182. % ---      diy       is the day of the year - 1 (i.e., Jan 1 is day 0).
  183. % ---      golden    is the number of the year in the Mentonic cycle, used to
  184. % ---                determine the position of the calender moon.
  185. % ---      epact     is the age of the calender moon (in days) at the beginning
  186. % ---                of the year.  To calculate epact, two century-based
  187. % ---                corrections are applied:
  188. % ---                Gregorian:      (3 * cent)/4 - 12
  189. % ---                      is the number of years such as 1700, 1800 when
  190. % ---                      leap year was not held.
  191. % ---                Clavian:      (((8 * cent) + 5) / 25) - 5
  192. % ---                      is a correction to the Mentonic cycle of about
  193. % ---                      8 days every 2500 years.  Note that this will
  194. % ---                      overflow 16 bits in the year 409600.  Beware.
  195. % --- The algorithm is accurate for the Gregorian calender only.
  196. %
  197. % --- The magic numbers used in the phase calculation are:
  198. % ---      29.5            The moon's period in days.
  199. % ---     177              29.5 scaled by 6
  200. % ---      22              (29.5 / 8) scaled by 6 (this gets the phase)
  201. % ---      11              ((29.5 / 8) / 2) scaled by 6
  202. %
  203. % --- Theoretically, this should yield a number in the range 0 .. 7.  However,
  204. % --- two days per year, things don't work out too well.
  205. %
  206. % --- Epact is calculated by the algorithm given in Knuth vol. 1 (Calculation
  207. % --- of Easter).  See also the article on Calenders in the Encyclopaedia
  208. % --- Britannica and Knuth's algorithm in CACM April 1962, page 209.
  209. %
  210. \def\phaseofmoon#1#2#3{{%
  211.   \@diy=#3 \advance\@diy by \ifcase#2                  % Jan 1 == 0
  212.       -1\or -1\or 30\or 58\or 89\or 119\or 150\or      % Jan .. Jun
  213.       180\or 211\or 241\or 272\or 303\or 333\fi        % Jul .. Dec
  214. %            if ((month > 2) && ((year % 4 == 0) &&
  215. %                ((year % 400 == 0) || (year % 100 != 0))))
  216. %                  diy++;            /* Leapyear fixup      */
  217.   \ifnum #2>2
  218.     \@x=#1 \@y=\@x \divide\@y by 4 \multiply\@y by 4 \advance\@x by -\@y
  219.     \ifnum \@x=0                    % month > 2 and maybe leap year
  220.       \@x=#1 \@y=\@x \divide\@y by 400 \multiply\@y by 400 \advance\@x by -\@y
  221.       \ifnum \@x=0                  % 2000 is a leap year
  222.       \advance\@diy by 1            % so it's one day later
  223.       \else                         % not 2000, check other '00's
  224.       \@x=#1 \@y=\@x \divide\@y by 100 \multiply\@y by 100 \advance\@x by -\@y
  225.       \ifnum \@x>0                  % not some other '00' year
  226.           \advance\@diy by 1        % it's still one day later
  227.       \fi                           % not odd century
  228.       \fi                           % not 2000-type century
  229.     \fi                             % not leapish year
  230.   \fi                               % not march or later
  231. %            cent = (year / 100) + 1;      /* Century number */
  232. %            golden = (year % 19) + 1;      /* Golden number */
  233.   \@cent=#1 \divide\@cent by 100 \advance\@cent by 1
  234.   \@golden=#1
  235.   \@y=#1 \divide\@y by 19 \multiply\@y by 19 \advance\@golden by -\@y
  236.   \advance\@golden by 1
  237. %            epact = ((11 * golden) + 20        /* Golden number */
  238. %            + (((8 * cent) + 5) / 25) - 5      /* 400 year cycle */
  239. %            - (((3 * cent) / 4) - 12)) % 30;   /* Leap year correction */
  240.   \@epact=11 \multiply\@epact by \@golden
  241.   \advance\@epact by 20
  242.   \@x=8 \multiply\@x by \@cent \advance\@x by 5
  243.   \divide\@x by 25 \advance\@x by -5
  244.   \advance\@epact by \@x
  245.   \@x=3 \multiply\@x by \@cent \divide\@x by 4 \advance\@x by -12
  246.   \advance\@epact by -\@x
  247.   \@y=\@epact \divide\@y by 30 \multiply\@y by 30 \advance\@epact by -\@y
  248. %      if (epact <= 0)
  249. %            epact += 30;                  /* Age range is 1 .. 30 */
  250. %      if ((epact == 25 && golden > 11) || epact == 24)
  251. %            epact++;
  252.   \ifnum \@epact<0
  253.     \advance\@epact by 30
  254.   \fi
  255.   \ifnum \@epact=25
  256.     \ifnum \@golden>11
  257.       \advance \@epact by 1
  258.     \fi
  259.   \else
  260.     \ifnum \@epact=24
  261.       \advance \@epact by 1
  262.     \fi
  263.   \fi
  264. %
  265. % --- Calculate the phase, using the magic numbers defined above.
  266. % --- Note that phase may be equal to 8 (== 0) on two days of the year
  267. % --- due to the way the algorithm was implemented.
  268. % ---      phase = (((((diy + epact) * 6) + 11) % 177) / 22) & 7;
  269. %
  270.   \@x=\@diy \advance\@x by \@epact \multiply\@x by 6 \advance\@x by 11
  271.   \@y=\@x \divide\@y by 177 \multiply\@y by 177 \advance\@x by -\@y
  272.   \divide\@x by 22
  273.   \ifcase\@x \NewMoon\or \WaxCresMoon\or \FirstQuarterMoon\or
  274.       \WaxGibMoon\or \FullMoon\or \WaneGibMoon\or
  275.       \LastQuarterMoon\or \WaneCresMoon\or \NewMoon\fi}}
  276.  
  277. REVISION HISTORY
  278.  
  279. 1.00--0   3-Aug-1990  First version
  280. 1.00--1   4-Aug-1992  Corrected \dayofweek: it was generating
  281.                       additional spaces before the day-name: this was
  282.                       significant in {tabular} environments, and
  283.                       screwed up alignment no end.  Disabled the
  284.                       \phaseofmoon definitions, which are of little
  285.                       interest to most people.
  286.  
  287. % --- End of dates.sty
  288.  
  289.